package com.zh.webcommon.common.param;

import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

import static com.zh.webcommon.CommonConst.GSON;

/**
 * 包装响应Response的数据
 *
 * @author ZH
 * @date 16:20 2020/12/29
 */
@Slf4j
public final class ResponseDataWrapper {
//    private static final String REGEX_PASSWORD = "(\"password\"[\\s]*:[\\s]*\")(.*?)(\")";

    private ResponseDataWrapper() {
    }

    /**
     * 将对象转为json数据，并包装为ByteBuffer返回
     *
     * @param object
     * @return
     */
    public static ByteBuffer wrapJson(Object object) {
        String jsonData = GSON.toJson(object)/*.replaceAll(REGEX_PASSWORD, "$1$3")*/;
        return ByteBuffer.wrap(jsonData.getBytes());
    }

}
